package com.snowleopard.findpeople.service.mgmt;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.snowleopard.common.base.BaseDao;
import com.snowleopard.common.base.BaseServiceImpl;
import com.snowleopard.findpeople.dao.mgmt.ParameterDao;
import com.snowleopard.findpeople.entity.mgmt.Parameter;

@Service
@Transactional
public class ParameterManager extends BaseServiceImpl<Parameter, String> {

    // parameter 表在第一次使用时完全加载, 提高页面反应速度
    private static final Map<String, List<Parameter>> paramMap = new HashMap<String, List<Parameter>>();

    @Autowired
    private ParameterDao parameterDao;

    @Override
    protected BaseDao<Parameter, String> getDao() {
        return parameterDao;
    }

    public List<Parameter> getByCode(String code) {
        
        List<Parameter> paramList= paramMap.get(code);
        
        if(paramList==null){
            paramList=parameterDao.findBy("code", code);
            paramMap.put(code, paramList);
        }
        
        return paramList;
    }
}
